package com.jiyun.service.impl;

import com.jiyun.entity.Order;
import com.jiyun.entity.Reviews;
import com.jiyun.entity.Tavern;
import com.jiyun.entity.UserFavoriteHotels;
import com.jiyun.mapper.OrderMapper;
import com.jiyun.mapper.TavernMapper;
import com.jiyun.mapper.UserFavoriteHotelsMapper;
import com.jiyun.service.OrderService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (Order)表服务实现类
 *
 * @author LYT
 * @since 2025-02-13 09:01:59
 */
@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
        implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private TavernMapper tavernMapper;

    @Autowired
    private UserFavoriteHotelsMapper userFavoriteHotelsMapper;



    @Override
    public List<Order> findOrder(Integer userId) {
        return orderMapper.findOrder(userId);
    }

    @Override
    public List<Reviews> findTavern(Integer tavernId) {
        Tavern tavern1 = tavernMapper.selectById(tavernId);
        List<Reviews> tavern = orderMapper.findTavern(tavernId);
        System.out.println("---------------------------------------------vern1 = " + tavern);
        int s = tavern.size();
        List<Order> orders = orderMapper.findTavernNumber(tavernId);
        for (Order order : orders) {
            orderMapper.updateOrder(tavernId,s);
        }

        return tavern;
    }

    @Override
    public List<Tavern> findLiKedTavern(Integer userId) {
        return userFavoriteHotelsMapper.findLiKedTavern(userId);
    }
}
